package com.lili.uitl;

import com.lili.service.UserService;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * java类简单作用描述
 *
 * @Description: java类作用描述
 * @Author: hf
 * @CreateDate: 2019/6/21 14:38
 * @UpdateUser: hf
 * @UpdateDate: 2019/6/21 14:38
 * @UpdateRemark: The modified content
 * @Version: 1.0
 */

public class ShiroUtils {

    private static Map<String, String> USER_MAP = new HashMap<>();


    public static String getUserId() {
        Object principal = SecurityUtils.getSubject().getPrincipal();
        return principal.toString();
    }

    public static String getUserLoginName(UserService userService) {
        String userId = getUserId();
        if (StringUtils.isBlank(USER_MAP.get(userId))) {
            USER_MAP = userService.selectAllUser();
        }
        return USER_MAP.get(userId);
    }
}
